<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header('分类列表')"></head>
<style type="text/css">
.ellipsis .btn-group{
    position: absolute;
    margin-top: -10px;
}
</style>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="cat-form">
					<div class="select-list">
						<ul>
							<li>类目名称：<input type="text" name="catName" />
							</li>
							<li>类目状态：<select name="visible"  th:with="type=${@dict.getType('cms_cat_visible')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}"  th:value="${dict.dictValue}"  th:text="${dict.dictLabel}">显示</option>

							</select>
							</li>
							<li><a class="btn btn-primary btn-rounded btn-sm"
								onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm"
								onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<div class="btn-group" shiro:hasPermission="cms:cat:edit">
					<button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">状态 <span class="caret"></span>
					</button>
					<ul class="dropdown-menu" id="catVisible" th:with="type=${@dict.getType('cms_cat_visible')}">
						<li  th:each="dict : ${type}"  th:data-id="${dict.dictValue}" ><a href="javascript:void(0)" th:text="${dict.dictLabel}"></a></li>
					</ul>
				</div>
				<a class="btn btn-success" onclick="$.operate.add(0)"
					shiro:hasPermission="cms:cat:add"> <i class="fa fa-plus"></i>
					新增
				</a> <a class="btn btn-primary" onclick="$.operate.edit()"
					shiro:hasPermission="cms:cat:edit"> <i class="fa fa-edit"></i>
					修改
				</a> <a class="btn btn-info" id="expandAllBtn"> <i
					class="fa fa-exchange"></i> 展开/折叠
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-tree-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>

	<div th:include="include :: footer"></div>
	<script th:inline="javascript">
		var addFlag = [[${@permission.hasPermi('cms:cat:add')}]];
		var editFlag = [[${@permission.hasPermi('cms:cat:edit')}]];
		var removeFlag = [[${@permission.hasPermi('cms:cat:remove')}]];	
		var detailFlag  = [[${@permission.hasPermi('cms:cat:detail')}]];
		var datas = [[${@dict.getType('sys_show_hide')}]];
		var prefix = ctx + "cms/cat";
		
		$(function() {			
		    var options = {
		        code: "catId",
		        parentCode: 'parentId',
		        uniqueId: "catId",
		        expandAll: false,
		        expandFirst: false,
		        url: prefix + "/list",
		        detailUrl: prefix + "/detail/{id}",
		        createUrl: prefix + "/add/{id}",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove/{id}",
		        modalName: "内容类目",
		        columns: [{
                    field: 'selectItem',
                    radio: true
                 },{
					field: 'catId',
					title: '类目Id'
				},
                 {
		            title: '类目名称',
		            field: 'catName',
		            formatter: function(value, row, index) {
		                if ($.common.isEmpty(row.catIcon)) {
		                    return row.catName;
		                } else {
		                    return '<i class="' + row.catIcon + '"></i> <span class="nav-label">' + row.catName + '</span>';
		                }
		            }
		        },
		        {
		        	   field: 'createBy',
			            title: '创建人Id'
		        },
		        {
		            field: 'catUrl',
		            title: '类目路径',
		            align: "left"
		        },
		        {
		            field: 'orderNo',
		            title: '排序',
		            align: "left"
		        },
					{
						field: 'keywords',
						title: '关键词',
						align: "left",
						visible:false
					},
					{
						field: 'description',
						title: '描述',
						align: "left",
						visible:false
					},
		        {
		            field: 'visible',
		            title: '状态',
		            align: "left",
					formatter: function(value, row, index) {
						return $.table.selectDictLabel([[${@dict.getType('cms_cat_visible')}]], value);
					}
		        },
		        {
		            field: 'createTime',
		            title: '创建时间',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: "left",
		            formatter: function(value, row, index) {
		                var actions = [];	               
		                actions.push('<a class="' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.catId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.catId + '\')"><i class="fa fa-trash"></i>删除</a>');
		                actions.push('<a class="' + detailFlag + '" href="#" onclick="$.operate.detail(\'' + row.catId + '\')"><i class="fa fa-search"></i>详情</a> ');
		                if(row.parent){
		                actions.push('<a class="' + addFlag + '" href="#" onclick="$.operate.add(\'' + row.catId + '\')"><i class="fa fa-plus"></i>添加下级类目</a>');
		                }
		                return $.table.dropdownToggle(actions.join(''));
		            }
		        }]
		    };
		    $.treeTable.init(options);
		});
		//修改分类状态
		$('#catVisible>li').click(function(e) {
			//获取选中的行
			var pam ={},chooseData =$("#" + table.options.id).bootstrapTreeTable('getSelections');
			if (chooseData.length>0)
			{
				pam.catId=chooseData[0].catId;
				pam.visible=$(this).attr("data-id");
				$.modal.confirm("确认要修改选的类目状态吗？子节点将修改为一样的状态！", function() {
					$.operate.post(prefix + "/editCatVisible", pam);
				})
			}
			else{
				$.modal.alert("请选择一项");

			}
		});
	</script>
</body>
</html>